package cn.gz.demo.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.gz.demo.R;
import cn.gz.demo.bean.Product;
import cn.gz.demo.databinding.AdapterRightListBinding;
import cn.gz.demo.utils.NumberUtil;

/**
 * Created by fangzhu on 2015/4/23.
 */
public class RightAdapter extends RecyclerView.Adapter<RightAdapter.MyViewHolder> {
    private Activity context;
    private List<Product> list;

    public RightAdapter(Activity activity, List<Product> response) {
        this.context = activity;
        this.list = response;
    }


    @Override
    public RightAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_right, parent, false);
        return new RightAdapter.MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RightAdapter.MyViewHolder holder, int position) {
        final Product product = list.get(position);
        holder.binding.tvItem1.setText(NumberUtil.beautifulDouble(product.getLast()));
        holder.binding.tvItem2.setText(NumberUtil.beautifulDouble(product.getSell() - product.getLastClose()));
        holder.binding.tvItem3.setText(NumberUtil.beautifulDouble(product.getUpDownRate()));
        holder.binding.tvItem4.setText(NumberUtil.beautifulDouble(product.getOpen()));
        holder.binding.tvItem5.setText(NumberUtil.beautifulDouble(product.getHigh()));
        holder.binding.tvItem6.setText(NumberUtil.beautifulDouble(product.getLow()));
        holder.binding.tvItem7.setText(NumberUtil.beautifulDouble(product.getLastClose()));
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private AdapterRightListBinding binding;

        public MyViewHolder(View view) {
            super(view);
            binding = DataBindingUtil.bind(view);
        }
    }
}